package com.example.springblog.config;

import com.example.springblog.enums.ResultCodeEnum;
import com.example.springblog.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExceptionAdvice {
    @ExceptionHandler
    public Result handler(Exception e){
        log.info("发生异常: e: ",e);
        return Result.fail(e.getMessage());
    }

    @ExceptionHandler
    public Result handler(UnsupportedOperationException e){
        log.info("发生异常: e: ",e.getMessage());
        return Result.fail(e.getMessage() , ResultCodeEnum.PARAM_INVILD.getCode());
    }
}
